<?php
class IndexAction extends CommonAction {

	// 框架首页
	public function index() {
		// print_r($_SESSION);
		if (isset ( $_SESSION [C ( 'USER_AUTH_KEY' )] )) {
			//显示菜单项
			$menu = array ();

			//读取数据库模块列表生成菜单项
			$node = M ( "Node" );
			$id = $node->getField ( "id" );
			$where ['level'] = 2;
			$where ['status'] = 1;
			$where ['pid'] = $id;
			$list = $node->where ( $where )->field ( 'id,name,group_id,title' )->order ( 'sort asc' )->select ();
			$accessList = $_SESSION ['_ACCESS_LIST'];
			foreach ( $list as $key => $module ) {
				if (isset ( $accessList [strtoupper ( APP_NAME )] [strtoupper ( $module ['name'] )] ) || $_SESSION ['administrator']) {
					//设置模块访问权限
					$module ['access'] = 1;
					$menu [$key] = $module;
				}
			}

			if (! empty ( $_GET ['tag'] )) {
				$this->assign ( 'menuTag', $_GET ['tag'] );
			}
			//dump($menu);
			$this->assign ( 'menu', $menu );

			$this->assign('test', 'aaa');
		}
		C ( 'SHOW_RUN_TIME', false ); // 运行时间显示
		C ( 'SHOW_PAGE_TRACE', false );

				 // $this->assign('dirlist', $this->dirlist('D:/xampp/htdocs/google_code/ellacms/public/files/'));
		$this->assign('dirlist', $this->dirlist('E:/xampp/htdocs/google_code/dwz_thinkphp/public/files/'));

		$this->display ();
	}



	function test(){
		echo 'test';
	}

	public $str;

	function dirlist($path){
		$dir = dir($path);
		//	echo $path.'<br>';
		while( $file = $dir->read()){
			// $hd = $path.'/'.$file;
			// $hd = $file;
			// echo $file;

			$str_arr = explode('files', $path);

			//file ext
			$ext_arr = explode('.', $file);

			if(  ($file != '.') && ($file != '..') && (!is_dir($path.$file))  ){
				// var_dump(is_dir($path.$file));
				// echo $file;
				// echo '<li><a href="main.html" target="navTab" rel="main">a</a></li>';


				$media = array('swf', 'jpg', 'gif', 'bmp');
				$zip = array('rar', 'zip');


				if( $ext_arr[1] == 'html' || $ext_arr[1] == 'htm'){

					$this->$str .= '<li><a href="__ROOT__/public/files'.$str_arr[1].$file.'" target="navTab" rel="'.$str_arr[1].$file.'" class="controler">'.$file.'</a></li>';
				}
				else if ( in_array($ext_arr[1], $media ) ){
					$this->$str .= '<li><a href="__ROOT__/public/view.php?ty='.$ext_arr[1].'&file='.$str_arr[1].$file.'" target="navTab" rel="'.$str_arr[1].$file.'" external="true" class="controler">'.$file.'</a></li>';
				}
				else if ( in_array($ext_arr[1], $zip ) ){
					$this->$str .= '<li><a href="__ROOT__/public/zip.php?file='.$str_arr[1].$file.'" target="navTab" rel="'.$str_arr[1].$file.'" external="true" class="controler">'.$file.'</a></li>';
				}
			}

			if( is_dir($path.$file) && ($file != '.') && ($file != '..') ){
				// echo '<li><a href="demo/common/ajaxTimeout.html" target="navTab">a9</a><ul>';
				$this->$str  .= '<li><a  target="navTab" class="controler" rel="'.$str_arr[1].$file.'">'.$file.'</a><ul>';

				$this->dirlist($path.$file.'/');

				// $this->$str .= '<li><a href="main.html" target="navTab" rel="main">sss</a></li>';
				// echo '</ul></li>';
				$this->$str .= '</ul></li>';
			}
		}
		return $this->$str;
	}

}
?>